package com.demo.reentrantLock;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class EndVolatitle {

    //监控线程
    private Thread monitorThread;
    private volatile boolean stop = false;
    //启动监控线程
    public void start(){
        monitorThread = new Thread(() -> {
            while (true) {
                Thread thread = Thread.currentThread();
                //是否被打断
                if (stop) {
                    log.debug("料理后事");
                    break;
                }
                try {
                    Thread.sleep(1000);
                    log.debug("执行监控记录");
                } catch (InterruptedException e) {
                    // e.printStackTrace();
                }
            }
        }, "monitor");

    }

    //停止监控线程
    public void stop(){
        stop = true;
        monitorThread.interrupt();
    }
}
